import Vue from 'vue'
import Router from 'vue-router'
import dataFillRouter from './modules/dataFilling'
import dataTaskRouter from './modules/dataTask'
import dictionaryRouter from './modules/dictionary'
import aggreReportRouter from './modules/aggregateReport'
import reportRouter from './modules/report'
Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  // {
  //   path: '/',
  //   name: 'Layout',
  //   component: Layout
  // },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  // {
  //   path: '/404',
  //   component: () => import('@/views/404'),
  //   hidden: true
  // },

  // {
  //   path: '/dataTask',
  //   component: Layout,
  //   // redirect: '/dataTask/table',
  //   name: 'DataTask',
  //   meta: { title: '数据任务', roles: ['市级管理员', '市级审核员'], icon: 'el-icon-s-data' },
  //   children: [
  //     {
  //       path: 'taskTemplate',
  //       name: 'TaskTemplate',
  //       component: () => import('@/views/dataTask/taskTemplate/list.vue'),
  //       meta: { title: '任务模板', roles: ['市级管理员', '市级审核员'], icon: 'el-icon-s-order' }
  //     },
  //     {
  //       path: 'taskPublish',
  //       name: 'TaskPublish',
  //       component: () => import('@/views/dataTask/taskPublish/list.vue'),
  //       meta: { title: '任务发布', roles: ['市级管理员'], icon: 'el-icon-s-order' }
  //     },
  //     {
  //       path: 'dataTemplate',
  //       name: 'dataTemplate',
  //       component: () => import('@/views/dataTask/dataTemplate/index.vue'),
  //       meta: { title: '报表模板', roles: ['市级管理员'], icon: 'el-icon-s-order' }
  //     }
  //   ]
  // },
  // {
  //   path: '/dataFilling',
  //   component: Layout,
  //   // redirect: '/dataTask/table',
  //   name: 'DataFilling',
  //   meta: { title: '数据填报', icon: 'el-icon-s-claim' },
  //   children: [
  //     {
  //       path: 'workOrder',
  //       name: 'WorkOrder',
  //       component: () => import('@/views/dataFilling/workOrder/list.vue'),
  //       meta: { title: '工单填报', icon: 'el-icon-s-order' }
  //     },
  //     {
  //       path: 'workReview',
  //       name: 'WorkReview',
  //       component: () => import('@/views/dataFilling/workReview/list.vue'),
  //       meta: { title: '工单审核', icon: 'el-icon-s-order' }
  //     }
  //   ]
  // },

  // {
  //   path: '/authority',
  //   component: Layout,
  //   redirect: '/authority/account',
  //   name: '账户权限',
  //   meta: {
  //     title: '账户权限',
  //     icon: 'user'
  //   },
  //   children: [
  //     {
  //       path: 'account',
  //       component: () => import('@/views/authority/account/index'), // Parent router-view
  //       name: '账户管理',
  //       meta: { title: '账户管理' }
  //     }
  //     // {
  //     //   path: 'role',
  //     //   component: () => import('@/views/authority/role/index'),
  //     //   name: '角色管理',
  //     //   meta: { title: '角色管理' }
  //     // },
  //   ]
  // },
  // {
  //   path: '/dictionary',
  //   component: Layout,
  //   // redirect: '/Management',
  //   meta: { title: '字典管理', roles: ['市级管理员', '填报单位管理员'], icon: 'el-icon-s-platform' },
  //   children: [{
  //     path: 'Management',
  //     name: 'Management',
  //     component: () => import('@/views/dictionaryManagement/index'),
  //     meta: { title: '字典管理', roles: ['市级管理员', '填报单位管理员'], icon: '' }
  //   }]
  // },
  {
    path: '/workOrder',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'detail',
        name: 'Detail',
        component: () => import('@/views/dataFilling/workOrder/detail.vue'),
        meta: { title: '工单详情', icon: '' }
      }
    ]
  },
  {
    path: '/workReview',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'reviewdetail',
        name: 'Reviewdetail',
        component: () => import('@/views/dataFilling/workReview/detail.vue'),
        meta: { title: '审核详情', icon: '' }
      }
    ]
  },
  {
    path: '/Task',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'taskDetail',
        name: 'TaskDetail',
        component: () => import('@/views/dataTask/taskPublish/taskDetail.vue'),
        meta: { title: '任务详情', icon: '' }
      }
    ]
  },
  {
    path: '/Report',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'detail',
        name: 'detail',
        component: () => import('@/views/aggregateReport/detail.vue'),
        meta: { title: '汇总详情', icon: '' }
      }
    ]
  },
  {
    path: '/aggReport',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'fixDetail',
        name: 'FixDetail',
        component: () => import('@/views/report/municipality/detail.vue'),
        meta: { title: '上报详情', icon: '' }
      }
    ]
  },
  {
    path: '/user-center',
    component: Layout,
    // redirect: '/user-center/baseinfo',
    hidden: true,
    children: [
      {
        path: 'baseinfo',
        name: 'Baseinfo',
        component: () => import('@/views/userCenter/index'),
        meta: { title: '用户中心', icon: '' }
      },
      {
        path: 'password',
        name: 'Password',
        component: () => import('@/views/userCenter/index'),
        meta: { title: '修改密码', icon: '' }
      }
    ]
  },
  // {
  //   path: '/aggregate-report',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'aggregate-report',
  //       name: 'AggregateReport',
  //       component: () => import('@/views/aggregateReport/list.vue'),
  //       meta: { title: '汇总报表', roles: ['市级管理员'], icon: 'form' }
  //     }
  //   ]
  // },
  {
    path: '/form',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        name: 'Form',
        component: () => import('@/views/form/luck.vue'),
        meta: { title: 'Form', icon: 'form' }
      }
    ]
  }

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]
export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    meta: {
      roles: ['dashbord']
    },
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '系统首页', roles: ['dashbord'], icon: 'dashboard' }
    }]
  },
  {
    path: '/authority',
    component: Layout,
    redirect: '/authority/account',
    name: '账户权限',
    meta: {
      title: '账户权限',
      icon: 'user',
      roles: ['dict']
    },
    children: [
      {
        path: 'account',
        component: () => import('@/views/authority/account/index'), // Parent router-view
        name: '账户管理',
        meta: { title: '账户管理', roles: ['dict'] }
      }
      // {
      //   path: 'role',
      //   component: () => import('@/views/authority/role/index'),
      //   name: '角色管理',
      //   meta: { title: '角色管理' }
      // },
    ]
  },
  dataFillRouter,
  dataTaskRouter,
  dictionaryRouter,
  aggreReportRouter,
  reportRouter,
  // 404 page must be placed at the end !!!
  // { path: '/:pathMatch(.*)', componname: '404', name: 'notMatch', hidden: true }
  { path: '*', redirect: '/404', hidden: true }
]
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
